﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DotNetNuke.Entities.Modules.Actions;
using TimelineNet.Library;


namespace dnnTimeline.DesktopModules {
    public partial class Timeline : DotNetNuke.Entities.Modules.PortalModuleBase, DotNetNuke.Entities.Modules.IActionable {

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e) {
            if(!Page.IsPostBack) {
                if(base.Settings.ContainsKey("Height")) {
                    double height = (double)base.Settings["Height"];
                    this.Timeline1.Height = new Unit(height);
                }
                string rss = "http://weblogs.asp.net/rchartier/rss.aspx";

                if(base.Settings.Contains("RSS"))
                {
                    rss = (string)base.Settings["RSS"];
                    if(rss == null || rss.Trim() == "") rss = "http://weblogs.asp.net/rchartier/rss.aspx";
                }

                HotZoneBand YEAR = new HotZoneBand(10, Enums.TimelineDateTime.YEAR, 100);
                HotZoneBand MONTH = new HotZoneBand(10, Enums.TimelineDateTime.MONTH, 100);
                HotZoneBand DAY = new HotZoneBand(80, Enums.TimelineDateTime.DAY, 100);

                Timeline1.Bands.Add(DAY);
                Timeline1.Bands.Add(MONTH);
                Timeline1.Bands.Add(YEAR);

                YEAR.Overview = true;
                MONTH.Overview = true;
                YEAR.TrackGap = new decimal(0.5);
                MONTH.TrackGap = new decimal(0.5);
                YEAR.TrackHeight = new decimal(1.0);
                MONTH.TrackHeight = new decimal(1.0);
                YEAR.Highlight = true;
                MONTH.Highlight = true;
                Timeline1.LabelWidth = 300;
                Timeline1.BubbleHeight = 300;
                Timeline1.BubbleWidth = 300;

                MONTH.SynchWith = 0;
                YEAR.SynchWith = 0;

                Timeline1.DataUrl = rss;

                Timeline1.DataSourceType = TimelineNet.DataSourceTypes.rss;
            }
        }

        #region IActionable Members

        public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions {
            get {
                ModuleActionCollection actions = new ModuleActionCollection();
                actions.Add(GetNextActionID(), "Timeline Settings", ModuleActionType.AddContent, "", "", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
                return actions;

            }
        }

        #endregion

    }
}